home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 172 < prev    next >
Encoding:
Text File  |  1996-08-05  |  6.3 KB  |  233 lines

  1. Path: news.telepac.pt!usenet
  2. From: a.leote@mail.telepac.pt (Carlos Leote)
  3. Newsgroups: comp.lang.c
  4. Subject: Why this DOS4GW CD identifier doesn┤t work
  5. Date: Wed, 03 Jan 1996 23:36:51 GMT
  6. Organization: telepac
  7. Message-ID: <4ccive$p4q@vivaldi.telepac.pt>
  8. NNTP-Posting-Host: ptm1_p1.telepac.pt
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Please,anybody could tell me what's wrong with this code?
  12. I'm trying to get CD ROM info calling MSCDEX services in
  13. Protected Mode with Watcom Dos4gw.
  14. I'm calling a Real Mode Interrupt like the book teatches
  15. but all i'll get so far it was tons of crashes.
  16. Many thanks in Advance.
  17. Carlos Leote
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <conio.h>
  23. #include <dos.h>
  24. #include "defines.h"
  25.  
  26. extern int  DPMI_allocRealSeg(int size,int *sel,int *r_seg);
  27. extern void DPMI_freeRealSeg(dword selector);
  28. extern void * DPMI_getSelectorBase(int sel);
  29. extern long DPMI_simRealInt(dword int_number,void *adress);
  30.  
  31. typedef struct{ unsigned char length;
  32.                 unsigned char subunit;
  33.                 unsigned char comcode;
  34.                 unsigned short status;
  35.                 char ununsed[8];
  36.                 unsigned char media;
  37.                 long address;
  38.                 short bytes;
  39.                 short sector;
  40.                 long volid;  } s_ioctli;
  41. typedef struct {unsigned char mode;
  42.                 unsigned char lowest;
  43.                 unsigned char highest;
  44.                 unsigned long address;   } s_track_data;
  45. struct s_cdrom_data{  unsigned short drives;
  46.                       unsigned char  first_drive;
  47.                       unsigned short current_track;
  48.                       unsigned long  track_position;
  49.                       unsigned char  track_type;
  50.                       unsigned char  low_audio;
  51.                       unsigned char  high_audio;
  52.                       unsigned char  disk_length_min;
  53.                       unsigned char  disk_length_sec;
  54.                       unsigned char  disk_length_frames;
  55.                       unsigned long  endofdisk;
  56.                       unsigned char  upc[7];
  57.                       unsigned char  diskid[6];
  58.                       unsigned long  status;
  59.                       unsigned short error; } cdrom_data;
  60. struct s_rmi{ long edi;
  61.               long esi;
  62.               long ebp;
  63.               long reserved;
  64.               long ebx;
  65.               long edx;
  66.               long ecx;
  67.               long eax;
  68.               short flags;
  69.               short es,ds,fs,gs,ip,cs,sp,ss;  } RMI;
  70.  
  71. int       Buf_len=1024;
  72. int       Buf_sel=0;
  73. int       Buf_rseg;
  74.  
  75. union REGS regs;
  76. struct SREGS sregs;
  77.  
  78. main()
  79. {
  80.   s_ioctli *ioctli;
  81.   s_track_data *track_data;
  82.   dword ciclo;
  83.   byte *real_pointer;
  84.  
  85.   regs.h.ah = 0x15;
  86.   regs.h.al = 0x00;
  87.   regs.w.bx = 0;
  88.   int386 (0x2f, ®s, ®s);
  89.   if (regs.w.bx == 0)   return (0); //  Return if no CDROM
  90.   cdrom_data.drives = regs.w.bx;
  91.   cdrom_data.first_drive = regs.w.cx;
  92.   
  93.   DPMI_allocRealSeg(Buf_len,&Buf_sel,&Buf_rseg); //Allocate real
  94. memory
  95.   real_pointer=DPMI_getSelectorBase(Buf_sel);    //linear Pointer to
  96. real memory
  97.   ioctli=(s_ioctli *)real_pointer;
  98.   track_data=(s_track_data *)(real_pointer+30);
  99.  
  100.   _fmemset(real_pointer,0,50);                  // set [real memory]=0
  101.   ioctli->length = sizeof (s_ioctli);
  102.   ioctli->comcode = 3;
  103.   ioctli->address = 30;
  104.   ioctli->bytes = sizeof (s_track_data);
  105.   track_data->mode = 0x0a;
  106.  
  107.   RMI.eax=0x00001510;                          
  108.   RMI.ecx=cdrom_data.first_drive;
  109.   RMI.es=Buf_rseg;      
  110.   RMI.edi=0;             
  111.   DPMI_simRealInt(0x2f,&RMI);                  // Real mode interrupt
  112.  
  113.   DPMI_freeRealSeg(Buf_sel);
  114. }
  115.  
  116. .386p
  117. .MODEL FLAT
  118. NOJUMPS
  119.  
  120. DATA    SEGMENT PUBLIC USE32 'DATA'
  121.         ASSUME DS:DATA
  122.  
  123. DATA    ENDS
  124.  
  125. CODE    SEGMENT PUBLIC USE32 'CODE'
  126.         ASSUME CS:CODE
  127.  
  128.     PUBLIC  DPMI_allocRealSeg
  129.     PUBLIC  DPMI_freeRealSeg
  130.     PUBLIC  DPMI_getSelectorBase
  131.     PUBLIC  DPMI_simRealInt
  132.  
  133. ;   Function:   DPMI_allocRealSeg
  134. DPMI_allocRealSeg PROC NEAR
  135.     ARG amount:DWORD,selector:DWORD,r_segment:DWORD
  136.           push    ebp
  137.           mov     ebp,esp
  138.           push    ebx
  139.  
  140.           xor     edx,edx
  141.           mov     ebx,amount      ; Get number of bytes requested.
  142.           add     bx,0fh          ; Round up to closest number of
  143. paragraphs.
  144.           shr     ebx,4           ;/16.
  145.           mov     eax,100h          ; Interrupt number.
  146.           int     31h             ; Allocate memory.
  147.           
  148.           jc      _ERR
  149.           mov     ebx,[selector]  ; Get address of selector.
  150.           mov     [ebx],dx        ; Save selector.
  151.           mov     ebx,[r_segment] ; Get address of selector.
  152.           mov     [ebx],ax        ; Save selector.
  153.           jmp     short _RET
  154. _ERR:     xor eax,eax             ; Zero return address.
  155.  
  156. _RET:     pop     ebx
  157.           pop     ebp
  158.           ret
  159. DPMI_allocRealSeg ENDP
  160.  
  161. ;   Function:   DPMI_freeRealSeg
  162.  
  163. DPMI_freeRealSeg PROC NEAR
  164.     ARG selector:DWORD
  165.           push    ebp
  166.           mov     ebp,esp
  167.           push    ebx
  168.  
  169.           mov     edx,selector    
  170.           mov     eax,101h        
  171.           int     31h             
  172.           
  173.           pop     ebx
  174.           pop     ebp
  175.           ret
  176. DPMI_freeRealSeg ENDP
  177.  
  178. ;   Function:   DPMI_getSelectorBase
  179.  
  180. DPMI_getSelectorBase PROC NEAR
  181.     ARG selector:DWORD
  182.           push    ebp
  183.           mov     ebp,esp
  184.           push    ebx
  185.  
  186.           mov     eax,6
  187.           mov     ebx,selector
  188.           int     31h
  189.           jc      _ERR6
  190.           mov     eax,ecx
  191.           shl     eax,16
  192.           mov     ax,dx
  193.           jmp     short _RET6
  194. _ERR6:    xor eax,eax             ; Zero return address.
  195.  
  196. _RET6:    pop     ebx
  197.           pop     ebp
  198.           ret
  199. DPMI_getSelectorBase ENDP
  200.  
  201. ;   Function:   DPMI_simRealInt
  202.  
  203. DPMI_simRealInt PROC NEAR
  204.     ARG interrupt:DWORD,adress:DWORD
  205.           push    ebp
  206.           mov     ebp,esp
  207.           push    ebx
  208.           push    es
  209.     
  210.           mov     ebx,interrupt   ;put the interrupt in bl
  211.           mov     edi,adress      ;put the address of dataStruct in
  212. edi
  213.           mov     eax,00000300h
  214.           mov     ecx,0
  215.           int     31h
  216.           jc      _ERR5           ;if the carry flag is set we have a
  217. failure
  218.           mov     eax,1
  219.           jmp     short _RET5
  220. _ERR5:    xor     eax,eax         ; Zero return address.
  221.  
  222. _RET5:    pop   es
  223.           pop   ebx
  224.           pop   ebp
  225.           ret
  226. DPMI_simRealInt ENDP
  227.  
  228. CODE  ENDS
  229.     END
  230.  
  231.  
  232.  
  233.